<template>
<el-menu default-active="2" :collapse="collapsed" collapse-transition router unique-opened class="el-menu-vertical-demo" background-color="#b80000" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox" style="height:150%;">
        <span style="font-size: 30px; font-family: 楷体; font-weight: bold;">快餐管理</span>
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
        <template slot="title">
            <i class="iconfont" :class="menu.icon"></i>
            <span>{{menu.menuname}}</span>
        </template>
        <el-menu-item-group>
            <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.url" :key="chmenu.menuid">
                <i class="iconfont" :class="chmenu.icon"></i>
                <span>{{chmenu.menuname}}</span>
            </el-menu-item>
        </el-menu-item-group>
    </el-submenu>
</el-menu>
</template>

<script>
export default {
    name: 'leftnav',
    data() {
        return {
            collapsed: false,
            allmenu: []
        }
    },
    // 创建完毕状态(里面是操作)
    created() {
        let res = {
            success: true,
            data: [],
            msg: 'success'
        }

        let routerList = [{
                userType: '0',
                icon: 'li-icon-xiangmuguanli',
                menuname: '用户管理',
                menus: [{
                        userType: '0',
                        icon: 'icon-cat-skuQuery',
                        menuname: '用户管理',
                        url: 'user/userList'
                    },
                    {
                        userType: '0',
                        icon: 'icon-cat-skuQuery',
                        menuname: '薪资管理',
                        url: 'user/salary'
                    }
                ]
            },
            {
                userType: '02',
                icon: 'li-icon-xiangmuguanli',
                menuname: '菜品管理',
                menus: [{
                    userType: '2',
                    icon: 'icon-cat-skuQuery',
                    menuname: '菜品管理',
                    url: 'food/foodList'
                },
                {
                    userType: '0',
                    icon: 'icon-cat-skuQuery',
                    menuname: '菜品管理',
                    url: 'food/foodListMenu'
                }]
            },
            {
                userType: '03',
                icon: 'li-icon-xiangmuguanli',
                menuname: '库存管理',
                menus: [{
                        userType: '03',
                        icon: 'icon-cat-skuQuery',
                        menuname: '库存管理',
                        url: 'material/materialList'
                    },
                    {
                        userType: '03',
                        icon: 'icon-cat-skuQuery',
                        menuname: '库存记录',
                        url: 'material/materialLog'
                    }
                ]
            },
            {
                userType: '01',
                icon: 'li-icon-xiangmuguanli',
                menuname: '订单管理',
                menus: [{
                    userType: '01',
                    icon: 'icon-cat-skuQuery',
                    menuname: '订单管理',
                    url: 'order/orderList'
                }]
            },
            {
                userType: '03',
                icon: 'li-icon-xiangmuguanli',
                menuname: '采购管理',
                menus: [{
                    userType: '0',
                    icon: 'icon-cat-skuQuery',
                    menuname: '采购管理',
                    url: 'purchase/purchaseLogAdmin'
                },{
                    userType: '3',
                    icon: 'icon-cat-skuQuery',
                    menuname: '采购记录',
                    url: 'purchase/purchaseLog'
                }]
            },
            {
                userType: '0',
                icon: 'li-icon-xiangmuguanli',
                menuname: '销售记录',
                menus: [{
                    userType: '0',
                    icon: 'icon-cat-skuQuery',
                    menuname: '销售记录',
                    url: 'saleLog/saleLog'
                },
                {
                    userType: '0',
                    icon: 'icon-cat-skuQuery',
                    menuname: '账单导出',
                    url: 'saleLog/billExport'
                }]
            },
            {
                userType: '0',
                icon: 'li-icon-xiangmuguanli',
                menuname: '数据统计',
                menus: [{
                    userType: '0',
                    icon: 'icon-cat-skuQuery',
                    menuname: '数据统计',
                    url: 'saleLog/MaterialStatistic'
                }]
            }
        ];

        //权限控制
        routerList.forEach(item => {
            let userType = window.localStorage.getItem("userType");
            if (item.userType.indexOf(userType) > -1) {
                item.menus.forEach((menu, index) => {
                    if (menu.userType.indexOf(userType) == -1)
                        item.menus.splice(index, 1);
                })
                if (item.menus && item.menus.length > 0) {
                    res.data.push(item)
                }
            }
        })

        this.allmenu = res.data
        // 监听
        this.$root.Bus.$on('toggle', value => {
            this.collapsed = !value
        })
    }
}
</script>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 240px;
    min-height: 400px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
    border: none;
    text-align: left;
}

.el-menu-item-group__title {
    padding: 0px;
}

.el-menu-bg {
    background-color: #1f2d3d !important;
}

.el-menu {
    border: none;
}

.logobox {
    height: 40px;
    line-height: 40px;
    color: #9d9d9d;
    font-size: 20px;
    text-align: center;
    padding: 20px 0px;
}

.logoimg {
    height: 40px;
}
</style>
